﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MODEL;

namespace CONTROLLER {
    public class LoginControl {

        public bool saveUser(string fname, string mname, string lname, string account) {
            try {
                Users users = new Users();
                Security sec = new Security();
                Entities entity = new Entities();

                users.Fname = fname;
                users.Mname = mname;
                users.Lname = lname;
                users.accountCode = sec.encrypt(account);
                users.createdDate = DateTime.Now;
                                
                entity.Users.Add(users);
                entity.SaveChanges();
                return true;
            } catch (Exception) {
                return false;
            }

        }

        public bool login(string uname, string pword) {

            try {
                Entities entity = new Entities();
                Security sec = new Security();
                string acc = sec.encrypt(uname + pword);
                var a = entity.Users.First(o => o.accountCode == acc);
                return true;
            } catch (Exception) {
                return false;
            }
        }
    }
}
